package com.shangyueshang.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.shangyueshang.mapper.GoodsAdvertiseFeeMapper;
import com.shangyueshang.model.GoodsAdvertiseFee;
import com.shangyueshang.request.PageReq;
import com.shangyueshang.response.PageResult;
import com.shangyueshang.service.GoodsAdvertiseFeeService;
import com.shangyueshang.utils.ExcelUtil;
import com.shangyueshang.utils.MyPageHelper;
import lombok.SneakyThrows;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.util.Collections;
import java.util.Map;

/**
 * @author: JokeyZheng
 * @email: zhengjingfeng@ruqimobility.com
 * @created: 2023/5/17 15:09
 * @version: v1.0.0
 */
@Service
public class GoodsAdvertiseFeeServiceImpl
        extends ServiceImpl<GoodsAdvertiseFeeMapper, GoodsAdvertiseFee> implements GoodsAdvertiseFeeService {

    @Override
    public PageResult<GoodsAdvertiseFee> findPage(PageReq pageReq) {
        Map<String, Object> lineParams = pageReq.getLineParams();
        PageInfo<GoodsAdvertiseFee> pageInfo =
                PageHelper.startPage(
                        pageReq.getPageNum(),
                        pageReq.getPageSize()
                ).doSelectPageInfo(
                        () -> getBaseMapper().queryAdvertiseFee(lineParams)
                );
        return MyPageHelper.getPageResult(pageInfo);
    }

    @Override
    @SneakyThrows
    public void export(PageReq pageReq, HttpServletResponse response) {
        pageReq.setPageSize(ExcelUtil.EXPORT_LIMIT);
        Map<String, Object> lineParams = pageReq.getLineParams();
        PageInfo<GoodsAdvertiseFee> pageResult =
                PageHelper.startPage(
                        pageReq.getPageNum(),
                        pageReq.getPageSize()
                ).doSelectPageInfo(
                        () -> getBaseMapper().queryAdvertiseFeeList(lineParams)
                );
        ExcelUtil.excelSimpleIncludeWrite(response, Collections.emptyList(), pageResult.getList(), GoodsAdvertiseFee.class);
    }
}
